package instance

import (
	"com.yy.api/common/logger"
	"com.yy.api/common/pojo/result"
	"com.yy.api/server/utils"
	"strconv"
)

func (i *ControllerImpl) Create() {
	logger.Default.Info("CreateInstance...")
	opts := i.AddOpt("rowImage", "", result.ParseCreateInstanceRowImageError("parse rowImage failed!")).
		AddOpt("portMappings", ",").
		AddOpt("gpuNum", "1"). //魔术数，需要进行处理
		AddOpt("name", "-1").  //魔术数，需要进行处理
		AddOpt("userId", formatUserId(utils.GenerateTimestampBasedUserID())).
		GetOpts()
	if reslt, ok := i.CreateInstance(opts); !ok {
		i.Fail(result.Error(result.AGENT_CREATE_CONTAINER_ERROR))
	} else {
		//TODO 包装一个VO进行返回
		i.Succeed(result.Success(reslt))
	}
}

func formatUserId(userId uint64) string {
	return strconv.FormatUint(userId, 10)
}
